/*
 * user-helper.js
 * smart home for amazon echo.
 *
 * Created by cx.
 * Copyright 2019, ttis.
 */

const db = require('./db-base')
const  {logI,logE}  = require('../../log.js')
/**
 * select query promise
 * @param {string} sql select sql string
 * @param {string} params params string
 * @returns {Promise<Object | boolean>} query promise
 */
exports.selectQuery = (sql, ...params) =>  new Promise(async (resolve, reject) => {
  try{
    let conn = await db.pool.getConnection();
    const [result] = await conn.query(sql,params);
    conn.release();
    resolve(result.length === 0 ? false : result)
    //const [result] = await db.conn.query(sql,params);
    //db.conn.release();
    //await db.pool.end();
    //db.conn.close();
    //resolve(result.length === 0 ? false : result)
  }catch (e){
    logE("C-S", "db", "db", `${JSON.stringify(e)}`, "null")
  }

})
